package org.example.domain;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MyApp {
    public static void main(String[] args) throws IOException {

        //定义mybatis主配置文件的名称，从类路径的跟开始。
        String config="mybatis.xml";
        //读取这个confing表示的文件
        InputStream in= Resources.getResourceAsStream(config);
        //创建了SqlSessinoFactoryBuilder对象
        SqlSessionFactoryBuilder bulider=new SqlSessionFactoryBuilder();
        //创建了SqlSessionFactory对象
        SqlSessionFactory factory =bulider.build(in);
        //获取SqlSession对象，从SqlSessionFactory中获取SqlSession
        SqlSession sqlSession=factory.openSession();
        //
        String sqlId="org.example.dao.studentdao.selectstudents";
        List<student> studentList=sqlSession.selectList(sqlId);
        for (student stu: studentList) {
            System.out.println(stu);
        }
        sqlSession.close();
    }
}
